#include "deviceModel.h"
#include "httpSession.h"
#include "log4z.h"

deviceModel::deviceModel():m_http(nullptr)
{
    init();
}

deviceModel::~deviceModel()
{

}

void deviceModel::init(){
    m_strFunc["list"] = &deviceModel::on_list;
    m_strFunc["channellist"] = &deviceModel::on_channellist;
}

void deviceModel::update(const std::vector<std::string> &path, void* user){
    m_http = static_cast<CHTTPSession*>(user);
    if (!m_http){
       return;
    }
    
    if(path.size() > 2)
    {
        auto it =  m_strFunc.find(path.at(3));
        if (it != m_strFunc.end()) {
			result res;
			(this->*(it->second))(&res);
		}
		else {
			// std::cout << "API not found or not supported for the request method. : " << ApiStr.c_str() << std::endl;
			return ;
		}
    }
    else
    {
        // std::cout << path.size() << std::endl;
    }
}

void deviceModel::on_list(result* res){
	// CData data = m_http->GetContent();
	// CJSONParse parse(data.c_str());
	// cJSON* root = parse.GetRootItem();
	// if (!root) { LOGFMTE("%s", data.c_str());return; }

	// CData licensePath;
	// CData machineCode;
	// parse.GetValueStr(root, "licensePath", licensePath);
	// parse.GetValueStr(root, "machineCode", machineCode);

    CData pageNum = m_http->get_paramField("licensePath");
	CData pageSize = m_http->get_paramField("licensePath");


	cJSON* JsonObject1 = cJSON_CreateObject();
	cJSON_AddItemToObject(JsonObject1, "code", cJSON_CreateNumber(200));
	cJSON_AddItemToObject(JsonObject1, "msg", cJSON_CreateString("成功"));
	cJSON_AddItemToObject(JsonObject1, "data", NULL);

	m_http->sendJson(JsonObject1);
}

void deviceModel::on_channellist(result* res){

}